new Vue({
  el: "#app",
  data() {
    return {
      jjnr: {},
      zc: {}, //暂时存放通过的数据
      xqym: [],
      FaDaDaIdentName: "",
      faDD: false,
      Domain_Business: "https://www.kdddy.cn/Image/",
      form: {
        Enterprise_Type: "",
        page: 1, //页数
        limit: 10, //每页数据条数
        token: $.cookie("token"),
      },
      formData: {},
      tableData: [], //表格数据
      total: 1,
      dialogForm: false,
      loading: false,
      title: "",
      multipleSelection: [],
    };
  },
  mounted() {
    console.log(getYMDHMSDate());
    this.getList(this.form);
    this.xq();
  },
  methods: {
    jj() {
      console.log(this.jjnr);
      this.jjnr.Row_Status = 99;
      let lArray = new Array();
      lArray.push(this.jjnr);
      let lJSONObject_enterprise_info = new Object();
      lJSONObject_enterprise_info.enterprise_info = lArray; //换表
      let lJSONObject_DataSet = new Object(); //Modify
      lJSONObject_DataSet.Modify = lJSONObject_enterprise_info; //换表
      console.log(lJSONObject_DataSet);
      // this.jjnr;
      // return;
      // const _this = this
      $.ajax({
        url: "https://service.kdddy.cn/donghui/clientOperation/generalSaveForClient",
        type: "POST",
        data: {
          Data: JSON.stringify(lJSONObject_DataSet),
        },
        success: function (Result) {
          console.log(Result);
          if (Result.Status === "success") {
            this.faDD = false;
            window.history.go(-1);
          }
        },
        // complete: function (XMLHttpRequest) {
        //   requestPretreatment(XMLHttpRequest); //config/config.js 响应预检
        // },
        dataType: "json",
      });
    },
    qd() {
      console.log(this.FaDaDaIdentName);
      this.zc.FaDaDaIdentName = this.FaDaDaIdentName;
      this.zc.Row_Status = 0;
      console.log(this.zc);
      let lArray = new Array();
      lArray.push(this.zc);
      let lJSONObject_enterprise_info = new Object();
      lJSONObject_enterprise_info.enterprise_info = lArray; //换表
      let lJSONObject_DataSet = new Object(); //Modify
      lJSONObject_DataSet.Modify = lJSONObject_enterprise_info; //换表
      console.log(lJSONObject_DataSet);
      const _this = this;
      // return;
      $.ajax({
        url: "https://service.kdddy.cn/donghui/clientOperation/generalSaveForClient",
        type: "POST",
        data: {
          Data: JSON.stringify(lJSONObject_DataSet),
        },
        success: function (Result) {
          console.log(Result);
          if (Result.Status === "success") {
            _this.faDD = false;
            // 延迟 1000 毫秒（即 1 秒）后显示成功消息
            setTimeout(() => {
              _this.$message({
                message: "同意成功!",
                type: "success",
              });
              // 再延迟 500 毫秒后返回上一页
              setTimeout(() => {
                window.history.go(-1);
              }, 500);
            }, 1000);
          } else {
            // 延迟 1000 毫秒（即 1 秒）后显示失败消息
            setTimeout(() => {
              _this.$message.error("提交失败！");
            }, 1000);
          }
        },
        // complete: function (XMLHttpRequest) {
        //   requestPretreatment(XMLHttpRequest); //config/config.js 响应预检
        // },
        dataType: "json",
      });
    },
    handleEdit(index, row) {
      console.log(index, row);
      sessionStorage.setItem(
        "Enterprise_Info_SerialNumber",
        row.Enterprise_Info_SerialNumber
      );
      window.location.href = "m.Authentication.html";
      // this.xq(row.Enterprise_Info_SerialNumber);
    },
    xq() {
      let a = sessionStorage.getItem("Enterprise_Info_SerialNumber");
      console.log(a);

      const _this = this;
      // return;
      $.ajax({
        headers: {
          AccessToken: $.cookie("token"), //会将数据转换为query string
        },
        // url: "http://192.168.10.92:8087/Enterprise/EnterpriseInfo",
        url: "https://service.kdddy.cn/donghuiForRequest/Enterprise/EnterpriseInfo",
        type: "get",
        data: {
          id: a,
        },
        success: function (Result) {
          console.log(Result);
          _this.xqym = Result.Data;
          // if (Result.Status === "success") {
          //   _this.$message.success("提交成功");
          //   window.history.go(-1);
          // } else {
          //   _this.$message.error("提交失败，请稍后再试");
          // }
        },
        // complete: function (XMLHttpRequest) {
        //   requestPretreatment(XMLHttpRequest); //config/config.js 响应预检
        // },
        dataType: "json",
      });
    },
    filterTag(value, row) {
      return row.Row_Status === value;
    },
    onSerach() {
      //查询方法
      let _this = this;
      console.log(_this.form.serachKey);
    },
    addContract() {
      console.log("跳转");
    },
    handleSizeChange(val) {
      this.form.page = 1;
      this.form.limit = val;
      this.getList(this.form);
    },
    handleCurrentChange(val) {
      this.form.page = val;
      this.getList(this.form);
    },
    getList(data) {
      //换页方法
      let _this = this;
      $.ajax({
        type: "POST",
        url: "https://service.kdddy.cn/donghui/generalBusiness/generalQueryByTableNameWithOriginal",
        data: {
          Data: "enterprise_info", //表名
          Condition: "Row_Status='88'",
        },
        success: function (Result) {
          // console.log(Result);
          // return;
          // if (Result.Status == "success") {
          _this.tableData = Result;
          // console.log(_this.tableData);
          // }
        },
        // complete: function (XMLHttpRequest) {
        //   _this.loading = false;
        //   if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
        //     window.parent.document.location.href =
        //       absolutepath() + XMLHttpRequest.getResponseHeader("CONTENTPATH");
        //   }
        // },
        dataType: "json",
      });
    },
    agree(row, id) {
      const result = confirm("是否为该企业认证法大大电签账号名称");
      console.log(row, id);
      this.zc = row;
      if (id == 0) {
        if (result) {
          this.faDD = true;
        } else {
          this.qd();
          // 用户点击了“取消”
          console.log("操作已取消");
        }
      } else {
        this.$confirm("是否拒绝该企业的申请?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            console.log(row);
            this.jjnr = row;
            this.jj();
            this.$message({
              type: "success",
              message: "拒绝成功!",
            });
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "已取消",
            });
          });
      }
      const _this = this;
      // let message = "";
      // if (id == 0) {
      //   message = "确认继续同意操作吗";
      //   this.$confirm(message, "提示", {
      //     confirmButtonText: "确定",
      //     cancelButtonText: "取消",
      //     type: "warning",
      //   })
      //     .then(() => {
      //       if (!_this.loading) {
      //         _this.loading = true;
      //         return;
      //         $.ajax({
      //           type: "POST",
      //           url: DomainName + "/GoodsInquiryKeyOriginal",
      //           data: {
      //             Primary_Key_Name: "User_Number", //主键名
      //             Primary_Key: row.User_Number,
      //             Data: "base_system_user_info",
      //           },
      //           success: function (Result) {
      //             console.log(Result);
      //             _this.formData = Result[0];
      //             _this.Update(row, id, "");
      //           },
      //           complete: function (XMLHttpRequest) {
      //             if (
      //               XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT"
      //             ) {
      //               window.parent.document.location.href =
      //                 absolutepath() +
      //                 XMLHttpRequest.getResponseHeader("CONTENTPATH");
      //             }
      //           },
      //           dataType: "json",
      //         });
      //       }
      //     })
      //     .catch(() => {
      //       this.$message({
      //         type: "info",
      //         message: "已取消",
      //       });
      //     });
      // } else {
      //   this.$prompt("请输入拒绝原因", "提示", {
      //     confirmButtonText: "确定",
      //     cancelButtonText: "取消",
      //   })
      //     .then(({ value }) => {
      //       if (!_this.loading) {
      //         _this.loading = true;
      //         $.ajax({
      //           type: "POST",
      //           url: DomainName + "/GoodsInquiryKeyOriginal",
      //           data: {
      //             Primary_Key_Name: "User_Number", //主键名
      //             Primary_Key: row.User_Number,
      //             Data: "system_user_info",
      //           },
      //           success: function (Result) {
      //             console.log(Result);
      //             _this.formData = Result[0];
      //             _this.Update(row, id, value);
      //           },
      //           complete: function (XMLHttpRequest) {
      //             if (
      //               XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT"
      //             ) {
      //               window.parent.document.location.href =
      //                 absolutepath() +
      //                 XMLHttpRequest.getResponseHeader("CONTENTPATH");
      //             }
      //           },
      //           dataType: "json",
      //         });
      //       }
      //     })
      //     .catch(() => {
      //       this.$message({
      //         type: "info",
      //         message: "取消输入",
      //       });
      //     });
      // }
    },
    Update(row, id, value) {
      const _this = this;
      console.log(row, id, value);

      return;
      let message = "";
      let datas = {};
      this.formData.Authentication_Date = getYMDHMSDate();
      if (id == 0) {
        if (row.Enterprise_Type == "1") {
          this.formData.Authentication = "1";
          this.formData.Authentication_Type = "3";
        } else if (row.Enterprise_Type == "0") {
          this.formData.Authentication = "0";
          this.formData.Authentication_Type = "2";
        }
        datas.User_Number = row.User_Number;
        datas.Enterprise_Info_SerialNumber = row.Enterprise_Info_SerialNumber;
        datas.Authentication_Status = 0;
        datas.Cause = value;
        message = "已同意";
      } else {
        if (row.Enterprise_Type == "1") {
          this.formData.Authentication_Type = "5";
        } else if (row.Enterprise_Type == "0") {
          this.formData.Authentication_Type = "4";
        }
        datas.User_Number = row.User_Number;
        datas.Enterprise_Info_SerialNumber = row.Enterprise_Info_SerialNumber;
        datas.Authentication_Status = 1;
        datas.Cause = value;
        message = "已拒绝";
      }
      $.ajax({
        type: "POST",
        url: DomainName + "/getEditAction?token=" + $.cookie("token"),
        data: {
          Data: JSON.stringify({
            Modify: { base_system_user_info: [this.formData] },
            Add: { enterprise_audit_log: [datas] },
          }),
        },
        success: function (Result) {
          if (Result.Status == "success") {
            _this.handldeRoleAdd(row.User_Number, (Result) => {
              _this.getList(_this.form);
              _this.$message({
                type: "success",
                message: "审核通过",
              });
            });
          }
        },
        // complete: function (XMLHttpRequest) {
        //   if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
        //     window.parent.document.location.href =
        //       absolutepath() + XMLHttpRequest.getResponseHeader("CONTENTPATH");
        //   }
        // },
        dataType: "json",
      });
    },
    handldeRoleAdd(User_Number, callback) {
      return;
      //分配权限
      $.ajax({
        type: "POST",
        url: DomainName + "/RoleAdd?grant_type=tourist",
        data: {
          User_Number,
        },
        success: function (Result) {
          callback(Result);
        },
        complete: function (XMLHttpRequest) {
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href =
              absolutepath() + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        },
        dataType: "json",
      });
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    delete(Brand_SerialNumber) {
      return;
      const _this = this;
      $.ajax({
        url: DomainName + "/ShopBrand_Original",
        type: "GET",
        async: false,
        data: { action: "jQueryAjax" },
        success: function (res) {
          console.log(res);
          for (let i = 0; i < res.length; i++) {
            if (res[i].Brand_SerialNumber == Brand_SerialNumber) {
              res[i].Row_Status = "1";
              _this.detel = res[i];
            }
          }
        },
        complete: function (XMLHttpRequest) {
          _this.loading = false;
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href =
              absolutepath() + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        },
      });
      let data = { Data: JSON.stringify({ Modify: { brand: [_this.detel] } }) };
      console.log(data);
      $.ajax({
        url: DomainName + "/GoodsFileEdit",
        type: "POST",
        async: false,
        data: data,
        error: function () {
          _this.$message.error("删除失败，请稍后再试");
        },
        complete: function (XMLHttpRequest) {
          _this.loading = false;
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href =
              absolutepath() + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        },
      });
    },
  },
});
